package com.lcredu.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 黎长容
 * @date 2025-09-06 14:21
 */
@Configuration
public class RabbitMQConfigTopic {
    public static final String QUEUE01 = "queue_Topic01";
    public static final String QUEUE02 = "queue_Topic02";

    public static final String ROUTER_KEY01 = "#.queue.*";
    public static final String ROUTER_KEY02 = "*.queue.*";

    public static final String TOPIC_EXCHANGE = "TopicExchange";


    //创建队列
    @Bean
    public Queue topic_queue01() {
        return new Queue(QUEUE01);
    }

    @Bean
    public Queue topic_queue02() {
        return new Queue(QUEUE02);
    }


    //创建交换机
    @Bean
    public TopicExchange topicExchange() {
        /**
         * 创建并返回一个主题交换机实例
         *
         * @return TopicExchange 返回配置好的主题交换机对象
         *         - 交换机名称：TOPIC_EXCHANGE
         *         - 持久化标志：true（交换机将在服务器重启后保留）
         *         - 自动删除标志：true（当没有队列绑定到此交换机时自动删除）
         */
        return new TopicExchange(TOPIC_EXCHANGE, true, true);
    }

    //绑定
    @Bean
    public Binding topicBinding01() {
        return BindingBuilder.bind(topic_queue01()).to(topicExchange()).with(ROUTER_KEY01);
    }

    @Bean
    public Binding topicBinding02() {
        return BindingBuilder.bind(topic_queue02()).to(topicExchange()).with(ROUTER_KEY02);
    }

}
